package org.rednebula.framework.core.context;

import java.io.Serializable;
import java.util.Enumeration;

import javax.servlet.ServletContext;

import org.rednebula.framework.core.BasicContext;
import org.rednebula.framework.core.utils.Struts2Utils;



public class InternalServletContext extends BasicContext implements
		Serializable {

	public InternalServletContext() {
		super();
		this.setName(APPLICTION);
	}
	public void close() {

	}
	public  ServletContext getServletContext(){
		return Struts2Utils.getServletContext();
	}
	
	public <T> T get(String key) {
		if(isSelf(key))
			return (T)getServletContext();
		return (T)getServletContext().getAttribute(key);
	}

	public <T> T get(Class<T> type) {
		return (T)getServletContext().getAttribute(type.getName());
	}

	public boolean has(String name) {
		if(name==null)return false;
		if(isSelf(name))return true;
		ServletContext servlet=getServletContext();
		Enumeration<String> ns= servlet.getAttributeNames();
		while(ns.hasMoreElements()){
			if(name.equals(ns.nextElement()))return true;
		}
		return false;
	}

}
